//
//  WBNavigationController.swift
//  DLSwift微博
//
//  Created by 丁浪涛 on 2016/11/7.
//  Copyright © 2016年 丁浪涛. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    //重写
    override func viewDidLoad() {
        super.viewDidLoad()
            navigationBar.isHidden = true

        }

    
    //设置 viewController 的左侧按钮为返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
    
        //如果不是栈底控制器才需要处理
        if childViewControllers.count  > 0 {
            viewController.hidesBottomBarWhenPushed = true;
            
            
            if let vc  = viewController as? WBBaseViewController {
                
                var  title = "返回"
                //判断控制器的级数
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
    
                vc.navItem.leftBarButtonItem = UIBarButtonItem(tite: title, target: self, action: #selector(poptoParent),isBackButton: true)
            }
        }
        
    
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func poptoParent()
    {
        popViewController(animated: true)
    }

}
